package com.easyexcle.demo.easyExcel.conver;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;

import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Author: lkz
 * @Title: TimeConverter
 * @Description: 时间转换 对应实体接收的参数是Date类型的
 * @Date: 2023/5/15 18:29
 */

public class TimeConverter implements Converter<Date> {



    /**
     * 导入支持的数据类型
     */
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * 导出支持的数据类型
     */
    @Override
    public Class supportJavaTypeKey() {
        return Date.class;
    }

    /**
     * 导入时，数据类型转换
     */
    @Override
    public Date convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public CellData convertToExcelData(Date date, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    //    @Override
//    public Date convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty property, GlobalConfiguration config) throws Exception {
//        // LocalDate日期转换
//        Date dateTime = DateUtil.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//        return dateTime;
//    }
//
//
//    /**
//     * 导出时，数据类型转换
//     * @param value
//     * @param contentProperty
//     * @param globalConfiguration
//     * @return
//     * @throws Exception
//     */
//    @Override
//    public WriteCellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
//        WriteCellData writeCellData = new WriteCellData();
//        writeCellData.setType(this.supportExcelTypeKey());
//
//        writeCellData.setStringValue(DateUtil.format(value,"yyyy-MM-dd"));
//        return writeCellData;
//
//    }









}
